package com.woniuxy.driverschool.controller;/* *
@author author
@create 2021-09-29 20:21
*/

import com.woniuxy.driverschool.entity.ResponseResult;
import com.woniuxy.driverschool.entity.TeachProgramme;
import com.woniuxy.driverschool.service.TeachProgrammeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TeachProgrammeController {

    @Autowired
    TeachProgrammeService teachProgrammeService;

    @GetMapping("/teachProgramme")
    ResponseResult<List<TeachProgramme>> getAllTeachProgrammes(){
        ResponseResult<List<TeachProgramme>> responseResult=new ResponseResult<List<TeachProgramme>>();
        responseResult.setData(teachProgrammeService.getAllTeachProgrammes());
        responseResult.setMessage("获取全部教学大纲成功");
        responseResult.setState(200);
        return responseResult;
    }

    @GetMapping("/teachProgramme/{teachProgrammeId}")
    ResponseResult<TeachProgramme> getTeachProgrammeById(@PathVariable("teachProgrammeId") int teachProgrammeId){
        ResponseResult<TeachProgramme> responseResult=new ResponseResult<TeachProgramme>();
        responseResult.setData(teachProgrammeService.getTeachProgrammeById(teachProgrammeId));
        responseResult.setMessage("获取教学大纲成功");
        responseResult.setState(200);
        return responseResult;
    }

    @PostMapping("/teachProgramme")
    ResponseResult addTeachProgramme(@RequestBody TeachProgramme teachProgramme){
       teachProgrammeService.addTeachProgramme(teachProgramme);
       ResponseResult responseResult=new ResponseResult();
       responseResult.setMessage("添加成功");
       responseResult.setState(200);
       return responseResult;
    }

    @PutMapping("/teachProgramme")
    ResponseResult editTeachProgramme(@RequestBody TeachProgramme teachProgramme){
        teachProgrammeService.modifyTeachProgramme(teachProgramme);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setMessage("添加成功");
        responseResult.setState(200);
        return responseResult;
    }

    @DeleteMapping("/teachProgramme/{teachProgrammeId}")
    ResponseResult removeTeachProgramme(@PathVariable("teachProgrammeId") int teachProgrammeId){
        System.out.println(teachProgrammeId);
        teachProgrammeService.removeTeachProgrammeById(teachProgrammeId);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setMessage("删除成功");
        responseResult.setState(200);
        return responseResult;
    }

}
